package dvdstore.client.gui.search;

import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.util.HashMap;
import java.util.Map;

import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JTextField;

import dvdstore.client.gui.AbstractGUIPanel;
import dvdstore.client.gui.dvd.DVDFields;

public class DVDSearchFieldsPanel extends AbstractGUIPanel {

	private Map <DVDFields, JTextField> fieldsMap;
	
	public DVDSearchFieldsPanel() {
		this.fieldsMap = new HashMap<DVDFields, JTextField>();
		this.title = "DVD Search";
		buildPanel();
	}
	
	@Override
	public void buildPanel() {
		setLayout(new GridBagLayout());
	       
		setBorder(BorderFactory.createTitledBorder(title));
	   
		GridBagConstraints c;
		int row = 0;
		int column = 0;
		
		for(DVDFields dvdField : DVDFields.values()) {
			
			column = 0;
		   
			c = new GridBagConstraints();
			c.gridx = column;
			c.gridy = row;
			c.gridwidth = 1;
			c.weightx = 0;
			c.weighty = 0;
			c.anchor = GridBagConstraints.FIRST_LINE_START;
			c.insets = new Insets(0, 0, 10, 10);      
	   
			add(new JLabel(dvdField.getLabel()), c);
			column ++;
	   
			c = new GridBagConstraints();
			c.gridx = column;
			c.gridy = row;
			c.gridwidth = 1;
			c.weightx = 1;
			c.weighty = 0;
			c.anchor = GridBagConstraints.FIRST_LINE_START;
			c.fill = GridBagConstraints.HORIZONTAL;
	   
			JTextField textField = new JTextField(1);
			fieldsMap.put(dvdField, textField);
			add(textField, c);
			row++;
		}
		
		c = new GridBagConstraints();
		c.gridx = 0;
		c.gridy = row;
		c.gridwidth = 2;
		c.weighty = 1;
		c.anchor = GridBagConstraints.PAGE_START;
		c.insets = new Insets(20, 0, 10, 0); 
		
		add(new DVDSearchButton("Search", this), c);
		
	}

	public Map<DVDFields, JTextField> getFieldsMap() {
		return fieldsMap;
	}
	
}
